﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server.Search.WebControls;
using System.Xml;
using System.IO;
using System.Reflection;

namespace OSSSearchRefiners.CusRefinementWebPart {
    [ToolboxItemAttribute(false)]
    public class CusRefinementWebPart : RefinementWebPart {

        public CusRefinementWebPart(){
            this.EnableViewState = true;
            this.UseDefaultConfiguration = false;
            this.ChromeType = PartChromeType.None;
        }

        protected override void OnInit(EventArgs e) {
            string s = GetRefinementXml();
            this.FilterCategoriesDefinition = s;

            base.OnInit(e);
        }

        protected string GetRefinementXml() {
            XmlDocument xmlDoc = new XmlDocument();
            using (Stream str = Assembly.GetExecutingAssembly().GetManifestResourceStream("OSSSearchRefiners.Refinement.xml")) {
                using (StreamReader rdr = new StreamReader(str)) {
                    xmlDoc.LoadXml(rdr.ReadToEnd());
                }
            }

            return xmlDoc.InnerXml;
        }
    }
}
